package view.Items;

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CTabFolder;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;

import view.Tabs.CharacterGUI;
import view.Tabs.HomePageGUI;

import controller.ControllerFunctions;

public class SearchResultItemGUI {

	protected int ID;
	protected String name;
	protected String gender;
	protected String species;
	protected String fictionalUniverses;
	protected CharacterGUI charGUIPage;

	public SearchResultItemGUI(int ID, String name, String gender, String species, String fictionalUniverses, int x, int y, Composite gr, final Display mainDisp, final CTabFolder ctfHome) {
		setID(ID);
		setName(name);
		setGender(gender);
		setSpecies(species);
		setFictionalUniverses(fictionalUniverses);
		final Color clrWhite = new Color(mainDisp, 255, 255, 255);
		Font fLine = new Font(mainDisp, new FontData("Ariel", 18, 0));

		Composite compResult = new Composite(gr, 0);
		compResult.setBounds(x, y, 750, 50);

		Label lblHLine = new Label(compResult, SWT.SEPARATOR | SWT.SHADOW_OUT | SWT.HORIZONTAL);
		lblHLine.setBounds(0, 0, 750, 10);
		lblHLine.setForeground(clrWhite);

		// name
		Label lblName = new Label(compResult, SWT.CENTER);
		lblName.setText(name);
		lblName.setBounds(60, 20, 240, 20);
		lblName.setForeground(clrWhite);

		// divider
		Label lblLine1 = new Label(compResult, SWT.CENTER & SWT.TOP);
		lblLine1.setText("|");
		lblLine1.setBounds(300, 12, 10, 40);
		lblLine1.setForeground(clrWhite);
		lblLine1.setFont(fLine);

		// gender
		Label lblGender = new Label(compResult, SWT.CENTER);
		lblGender.setText(gender != null ? gender : "");
		lblGender.setBounds(310, 20, 90, 20);
		lblGender.setForeground(clrWhite);

		// divider
		Label lblLine2 = new Label(compResult, SWT.CENTER & SWT.TOP);
		lblLine2.setText("|");
		lblLine2.setBounds(400, 12, 10, 40);
		lblLine2.setForeground(clrWhite);
		lblLine2.setFont(fLine);

		// species
		Label lblSpecies = new Label(compResult, SWT.CENTER);
		lblSpecies.setText(species != null ? species : "");
		lblSpecies.setBounds(410, 20, 120, 20);
		lblSpecies.setForeground(clrWhite);

		// divider
		Label lblLine3 = new Label(compResult, SWT.CENTER & SWT.TOP);
		lblLine3.setText("|");
		lblLine3.setBounds(530, 12, 10, 40);
		lblLine3.setForeground(clrWhite);
		lblLine3.setFont(fLine);

		// fictional universes
		Label lblFictionalUniverses = new Label(compResult, SWT.CENTER);
		lblFictionalUniverses.setText(fictionalUniverses != null ? fictionalUniverses : "");
		lblFictionalUniverses.setBounds(540, 20, 200, 20);
		lblFictionalUniverses.setForeground(clrWhite);

		// open the character page
		Button btnGoto = new Button(compResult, SWT.NONE);
		btnGoto.setText("GoTo");
		btnGoto.setBounds(10, 15, 40, 30);
		btnGoto.addSelectionListener(new SelectionAdapter() {

			@Override
			public void widgetSelected(SelectionEvent e) {
				if (HomePageGUI.get().characterPages.containsKey(getID()))
					ctfHome.setSelection(HomePageGUI.get().characterPages.get(getID()).getIndex());
				else
					ControllerFunctions.get().getCharacterDetails(getID());
			}
		});

	}

	public int getID() {
		return ID;
	}

	public void setID(int iD) {
		ID = iD;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getGender() {
		return gender;
	}

	public void setGender(String gender) {
		this.gender = gender;
	}

	public String getSpecies() {
		return species;
	}

	public void setSpecies(String species) {
		this.species = species;
	}

	public String getFictionalUniverses() {
		return fictionalUniverses;
	}

	public void setFictionalUniverses(String fictionalUniverses) {
		this.fictionalUniverses = fictionalUniverses;
	}

	public CharacterGUI getCharGUIPage() {
		return charGUIPage;
	}

	public void setCharGUIPage(CharacterGUI charGUIPage) {
		this.charGUIPage = charGUIPage;
	}

}
